<?php 
	session_start();
	if (isset($_SESSION['username']) && isset($_SESSION['uid'])) {
		require('../../Controller/MaintainSystem_controller.php');
		$admin = new MaintainSystem();
		$account = $_SESSION['username'];
		$uid = $_SESSION['uid'];
		if($admin->checkUser($account, $uid)) {
		}
		else{	
			echo "<script language='javascript'>";
			echo "window.open('../../login.php', '_top');";
			echo "</script>";	
			//header("location:../../login.php");
		}
	}else {
		header("location:../../login.php");
	}
?>

<html>

<head>
	<meta http-equiv="Content-Type" content="width=device-width; text-html; charset=utf-8" />
	<script type="text/javascript" src="../../CSS/bootstrap/js/jquery.js"></script>
    <script type="text/javascript" src="../../CSS/bootstrap/js/bootstrap.min.js"></script>	
	<link href="../../CSS/bootstrap/css/bootstrap.css" rel="stylesheet" />
	    <link rel="stylesheet" href="../CSS/bootstrap/css/font-awesome.css">	    
	<title>FaceTech</title>	        
	<style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="../../CSS/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
	<style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
      .sidebar-nav {
        padding: 9px 0;
      }
      .media, .media-body {
    		overflow:hidden;
    		*overflow:visible;
    		zoom:1;
    	}
    	.media {
    		margin-bottom: 10px;
    	}
    	.media .media {
    		margin-top: 20px;
    	}
    	.media .pull-left {
    		margin-right: 10px;
    	}
    	.media .pull-right {
    		margin-left: 10px;
    	}
    	.media .media-object {
    		display: block;
    	}
    	/* Media list */
    	.medias {
    		margin-top: 20px;
    		margin-left: 0;
    		list-style-type: none;
    	}
    	.medias .media {
    		padding-bottom: 10px;
    		border-bottom: 1px solid rgba(0,0,0,.07);
    	}
    	.medias > .media:last-child {
    		margin: 0;
    		border-bottom: none;
    	}
    	.medias > .media .media {
    		margin-bottom: 0;
    		padding-bottom: 0;
    		border-bottom: none;
    	} 
    	/* Media box */
    	.media-box {
    		margin-bottom: 10px;
    		padding: 10px;
    		background-color: #fff;
    		border: 1px solid rgba(0,0,0,.09);
    		-webkit-border-radius: 4px;
    		-moz-border-radius: 4px;
    		border-radius: 4px;
    		-webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    		-moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    		box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    	}
    	@media (max-width: 480px) {
    	    .media .pull-left,
    	    .media .pull-right  {
    	    	float: none;
    	    	display: block;
    	    	margin-bottom: 10px;
    	    }
    	    .media .pull-left {
    	        margin-right: 0;    
    	    }
    	    .media .pull-right {
    	        margin-left: 0;    
    	    }
    	}
    </style>
    <link href="../../CSS/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
	<link href="../../CSS/bootstrap/css/bbootstrap.min.css" rel="stylesheet" media="screen">
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->    
    <script language="javascript">
		function show(did){
			var xx=document.getElementById(did).style.display;
			if(xx==""){
				document.getElementById(did).style.display="none";
			}else{
				document.getElementById(did).style.display="";
			}
		}
	</script>
</head>

<body>

<div class="container">
				<div class="span12">
					<form class="navbar-form pull-left" action="./DelMsg.php" method="post" id="delMsgForm">
					<table class="table table-striped">
					  <thead>
					    <tr>
					      <th>SenderName</th>
					      <th>ReciverName</th>
					      <th>TimeStamp</th>
					      <th>MessageContent</th>
					      <th>Operation</th>
					    </tr>
					  </thead>
					  <tbody>
						  <?php 
							$msgData = $admin->showAllMessage();
							date_default_timezone_set("Asia/Taipei");
							while($msgInfo=mysql_fetch_row($msgData)){		
								echo <<<DONE
								<tr>
									<td>
									<img class="pull-left media-object" src="../../$msgInfo[2]" height="64" width="64" border="1"/>
									<h4>$msgInfo[1]</h4> <!--Seder-->
									</td>
									<td>
									<img class="pull-left media-object" src="../../$msgInfo[4]" height="64" width="64" border="1"/>
									<h4>$msgInfo[3]</h4> <!--Reciver-->
									</td>
									<td>
									<small> <!--TimeStamp-->
DONE;
									echo "<h4>".(date('Y/n/j g:i a', $msgInfo[5]))."</h4>";
								echo <<<DONE
									</small>	
									</td>
									<td>
									<h4>$msgInfo[6]</h4>	<!--Content-->
									</td>
									<td>
									<button class='btn btn-mini btn-primary' form="" align=center onclick="location.href='ModifyMessageForm.php?mid=$msgInfo[0]'">修改</button>
									<button class='btn btn-mini btn-primary' form='delMsgForm' align=center onclick="if(confirm('您確定要刪除訊息嗎?')) return true;else return false" name=delmid value=$msgInfo[0]>刪除</button>
									</td>								
DONE;
							}
						?>		
					</tbody>
					</table>
					</form>
	</div>
</div>	

    

</body>

</html>